<?php


namespace app\common\model;


use think\facade\Validate;
use think\Model;

class Shebei extends Model
{
    public function saveData($data)
    {
        $validate = Validate::make([
            'house_id' => 'require',
            'room_id' => 'require',
            'title' => 'require'
        ], [
            'house_id' => '宿舍楼栋必选',
            'room_id' => '宿舍必选',
            'title' => '设备信息必填'
        ]);
        if (!$validate->check($data)) {
            exception($validate->getError());
        }
        if (isset($data['id'])) {
            //更新
            $res = $this->where('id', $data['id'])->update($data);
        } else {
            //添加
            $data['create_time'] = time();
            $res = $this->insertGetId($data);
        }
        return $res;
    }
}